let ul=document.querySelector('.brand ul')
let arr=[]
let xhr =new XMLHttpRequest()
xhr.open('get','http://chst.vip:1234/api/getbrandtitle',false)
xhr.onload=function(){
    if(xhr.status===200){
        let res =JSON.parse(xhr.responseText)
        let an=res .result
        let lis=''
        an.forEach(item => {
            lis+=`
            <li>
                <h4>${item.brandTitle}</h4>
                <i class="iconfont icon-xiajiantou"></i>
                <div class="one"> 
                </div>
            </li>
            ` 
            arr.push(item.brandTitleId)
        });
        ul.innerHTML=lis
    }
}
xhr.send(null)



let one=document.querySelectorAll('.brand ul li .one')
arr.forEach((a,b) => {
    let xhr1=new XMLHttpRequest()
    xhr1.open('get',`http://chst.vip:1234/api/getbrand?brandtitleid=${a}`,false)
    xhr1.onload=function(){
        if(xhr1.status===200){
            let res1=JSON.parse(xhr1.responseText)
            let las=''
            res1.result.forEach((c,d,e)=>{
                las+=`
                <div class="two" brandId=${c.brandId} brandName=${c.brandName}>
                    <p>${d}</p>
                    <p>${c.brandName}</p>
                    <p>${c.brandInfo}</p>
                </div>
                `    
            })
            one[b].innerHTML=las
        }
    }
    xhr1.send(null)  
});

$('.one').slideUp(0);
$('.brand li').click(function(){
    $(this).find('.one').slideToggle().parent().siblings().find('.one').slideUp()
})


ul.onclick=function(e){
    var e = e || window.event;
    var target = e.target || e.srcElement;
    if(target.nodeName==='P'){
        localStorage.setItem('brandtitleid',target.parentNode.getAttribute('brandId'))
        localStorage.setItem('brandName',target.parentNode.getAttribute('brandName'))
        location.href = 'http://127.0.0.1:5500/js/day18/html/band.html';
    }
}